<h2>Collision Detection</h2>

<p>Finally we need to be able to know when the car has passed through
the finish line or hits a power-ups.  We call this &quot;collision
detection&quot; because we're trying to see when the car
&quot;collides&quot; or runs into something.</p>

<p>First, we'll need to get the <em>coordinates</em> of the things we
want to check for collisions.  Once you have a coordinate for two
things, you can make a <em>function</em> to compute how close they are
and use a <em>conditional</em> to see if that's close enough for a
collision.</p>

<p>To get the finish coordinate for a course,
use <code>course.getFinishCoord()</code>.  For the car,
use <code>car.getCoord()</code>.</p>

<p>A coordinate object has <em>methods</em> to get its latitude and a
longitude as numbers.  If your coord is named <code>coord</code> you
can access these by <code>coord.lat()</code>
and <code>coord.lng()</code>.</p>

<p>Now, use this code to tie this all together:</p>

<pre>
function detectCollisions() {
  if (AlmostEquals(racecarCoord.lat(),
                   finishCoord.lat()) &&
      AlmostEquals(racecarCoord.lng(),
                   finishCoord.lng())) {
    alert('Finished!');
  }
}

function AlmostEquals(a, b) {
   if (Math.abs(a - b) < 0.0001) {
     return true;
   }
   return false;
}
</pre>

<p>Now that you have the pieces, add in a call to detectCollisions in
your <code>everyFrame</code> function and try it out!</p>
